const accountList = []
/**
 * 用户注册
 */
export const mockRegister = {
    url:'/mock/account/register',
    method:'post',
    response:(config)=>{
        // 注册业务逻辑
        // 1. 获取用户名和密码
        const {username,password,headerimg} = config.body
        // 2. 保存用户信息
        // localStorage.setItem('USER',JSON.stringify({username,password,headerimg}))
        const user = {username,password,headerimg}
        accountList.push(user)
        // 3. 响应内容
        return {
            resultCode:1,
            resultInfo:'注册成功'
        }
    }
}

/**
 * 用户登录
 */
export const mockLogin = {
    url:'/mock/account/login',
    method:'post',
    response:(config)=>{
        // 登录业务逻辑
        // 1. 获取用户名和密码
        const {username,password,headerimg} = config.body
        // 2. 判断用户是否注册
        // let userstr = localStorage.getItem('USER')
        // let user = userstr? JSON.parse(userstr):''
        const user = accountList.find(item=>item.username==username && item.password==password)
        if(user){
            return {
                resultCode:1, 
                resultInfo: { 
                        username,
                        password,
                        headerimg
                } 
            }
        }else{
            return {
                resultCode:-1,
                resultInof:'账户出错'
            }
        }
    }
}

